package com.avast.personalbudgetapp.global.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import java.util.UUID;

import android.util.Log;

import com.avast.personalbudgetapp.global.constant.Constants;
import com.avast.personalbudgetapp.model.bean.TransactionDate;

/**
 * Application Util Class
 * 
 * @author hallac
 *
 */
public class AppUtil {
	
	public static Date convertStringToDate(String dateInString){
		SimpleDateFormat formatter = new SimpleDateFormat(Constants.APP_DATE_FORMAT, Locale.getDefault());
		Date date = null;
		try {
			date = formatter.parse(dateInString);
		} catch (ParseException e) {
			Log.e(AppUtil.class.getName(), e.getLocalizedMessage(), e);
		}
		return date;
	}
	
	public static TransactionDate getTransactionDate(String dateInString){
		Date date = convertStringToDate(dateInString);
	    Calendar cal = Calendar.getInstance();
	    cal.setTime(date);
	    int year = cal.get(Calendar.YEAR);
	    int month = cal.get(Calendar.MONTH);
	    int day = cal.get(Calendar.DAY_OF_MONTH);
	    return new TransactionDate(year, month, day);
	}
	
	public static String generateGuid(){
        UUID uuidObject = UUID.randomUUID();
        return uuidObject.toString();
	}

}
